package indi.zyj.springsecurity.controller;


import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RequestMapping("/test/hello")
    public String hello(){

        new Thread(()->{

            SecurityContext context = SecurityContextHolder.getContext();
            Authentication authentication = context.getAuthentication();
            User principal = (User) authentication.getPrincipal();

            System.out.println("身份信息：" + principal.getUsername());
            System.out.println("权限：" + authentication.getAuthorities());
            System.out.println("凭证：" + authentication.getPrincipal());

        }).start();

        return "我是受限资源！";
    }

}
